package complex;

/**
 * @Description //时间复杂度
 * @Author Administrator
 * @DATE 2020/10/25 16:15
 **/
public class TimeComplexity {

    /**
     * @param num
     * @Description O(1)
     **/
    public int o1(int num) {
        int i = 1;
        i = i * num;
        return i;
    }

    /**
     * @param num
     * @return int
     * @Description O(logN)
     **/
    public int oLogN(int num) {
        int i = 1;
        while (i < num) {
            i = i * 2;
        }
        return i;
    }

    /**
     * @param num
     * @return int
     * @Description O(N)
     **/
    public int oN(int num) {
        int i = 0;
        for (int j = 0; j < num; j++) {
            i += num;
        }
        return i;
    }

    /**
     * @param num1
     * @param num2
     * @return int
     * @Description O（NLogN）
     **/
    public int oNLogN(int num1, int num2) {
        int i = 0;
        for (int j = 0; j < num1; j++) {
            while (i < num2) {
                j = j * 2;
            }
            i = j;
        }
        return  i;
    }

    /**
     * @Description O（n^2）
     * @param num
     * @return int
     **/
    public int n2(int num){
        int i = 0;
        for (int j = 0; j < num ; j++) {
            for (int k = 0; k < num ; k++) {
                i ++;
            }
        }
        return i;
    }
}
